﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TTSModel;
using TTSIDAL;
using System.Data;
using System.Data.SqlClient;
namespace TTSDAL
{
    public class Package : BaseRepository<PackageInfo>, IPackage
    {
         #region 静态变量定义
        private const string PARM_ProductType = "@ProductType";
        private const string PARM_StartTime = "@StartTime";
        private const string PARM_EndTime = "@EndTime";
        private const string PARM_KCCSN1 = "@KCCSN1";
        private const string PARM_KCCSN2 = "@KCCSN2";
        private const string PARM_PEC = "@PEC";
        private const string PARM_CPC = "@CPC";
        private const string PARM_KCCSN = "@KCCSN";
        private const string PARM_NetWeight = "@NetWeight";
        private const string PARM_RLS = "@RLS";
        private const string PARM_QTY = "@QTY";
        private const string PARM_CountryOrigin = "@CountryOrigin";
        private const string PARM_WeekNum = "@WeekNum";
        private const string PARM_QCUser = "@QCUser";
        private const string PARM_PackageUser= "@PackageUser";
        private const string PARM_Remark = "@Remark";
        private const string PARM_ProductPackageStatus = "@ProductPackageStatus";
        #endregion

        #region 数据检索部分
        public IList<PackageInfo> LoadEntities()
        {
            return null;
        }
        public IList<PackageInfo> Package_GetListbyKCCSN(string _KCCSN)
        {
            SqlParameter parm = GetParameter();
            parm.Value = _KCCSN;
            return ExcuteSqlToGetEntities("PackageSending_SelectByKCCSN", parm);
        }
        public PackageInfo LoadEntity<T1>(T1 sn)
        {           
            return null;
        }
        public PackageInfo Package_GetbyKCCSN(string _KCCSN)
        {
            SqlParameter parm = GetParameter();
            parm.Value = _KCCSN;
            return ExcuteSqlToGetEntity("PackageSending_SelectByKCCSN", parm);
        }
        public IList<PackageInfo> PackageInfo_GetbyDT(string _productType, DateTime _startTime, DateTime _endTime)
        {
            SqlParameter[] parms = new SqlParameter[]
            { 
                new SqlParameter(PARM_ProductType, SqlDbType.NVarChar, 10),
                new SqlParameter(PARM_StartTime, SqlDbType.DateTime),
                new SqlParameter(PARM_EndTime, SqlDbType.DateTime),
            };
            parms[0].Value = _productType;
            parms[1].Value = _startTime;
            parms[2].Value = _endTime;
            return ExcuteSqlToGetEntities("PackageSending_SelectByDT", parms);
        }
        #endregion

        #region 重写基类方法
        public override PackageInfo GetEntityRecord(SqlDataReader rdr)
        {
            PackageInfo entity = new PackageInfo()
            {
                RecordTime= rdr.GetDateTime(1),
                KCCSN1 = rdr.GetValue(2).ToString(),
                KCCSN2= rdr.GetValue(3).ToString(),
                PEC = rdr.GetValue(4).ToString(),
                CPC=rdr.GetValue(5).ToString(),
                KCCSN=rdr.GetValue(6).ToString(),
                NetWeight=rdr.GetValue(7).ToString(),
                RLS=rdr.GetInt32(8),
                QTY=rdr.GetInt32(9),
                CountryOrigin=rdr.GetValue(10).ToString(),
                WeekNum=rdr.GetValue(11).ToString(),
                QCUser=rdr.GetValue(12).ToString(),
                PackageUser=rdr.GetValue(13).ToString(),
                Remark=rdr.GetValue(14).ToString(),
                ProductPackageStatus = rdr.GetValue(15).ToString(),
            };
            return entity;
        }

        public override PackageInfo GetEntityRecord()
        {
            PackageInfo entity = new PackageInfo();
            return entity;
        }

        public override string GetInsertsp()
        {
            return "PackageSending_Insert";
        }

        public override string GetUpdatesp()
        {
            return null;
        }

        public override string GetDeletesp()
        {
            return null;
        }

        public override SqlParameter GetParameter()
        {
            SqlParameter parm = new SqlParameter(PARM_KCCSN1, SqlDbType.NVarChar, 20);
            return parm;
        }

        public override SqlParameter[] GetParameters()
        {
            SqlParameter[] parms = new SqlParameter[]
            {
                new SqlParameter(PARM_ProductType,SqlDbType.NVarChar,10),
                new SqlParameter(PARM_KCCSN1,SqlDbType.NVarChar,20),
                new SqlParameter(PARM_KCCSN2,SqlDbType.NVarChar,20),
                new SqlParameter(PARM_PEC,SqlDbType.NVarChar,10),  
                new SqlParameter(PARM_CPC,SqlDbType.NVarChar,10),
                new SqlParameter(PARM_KCCSN,SqlDbType.NVarChar,20),
                new SqlParameter(PARM_NetWeight,SqlDbType.NVarChar,10),
                new SqlParameter(PARM_RLS,SqlDbType.Int),  
                new SqlParameter(PARM_QTY,SqlDbType.Int),
                new SqlParameter(PARM_CountryOrigin,SqlDbType.NVarChar,10),
                new SqlParameter(PARM_WeekNum,SqlDbType.NVarChar,10),
                new SqlParameter(PARM_QCUser,SqlDbType.NVarChar,10),  
                new SqlParameter(PARM_PackageUser,SqlDbType.NVarChar,10),  
                new SqlParameter(PARM_Remark,SqlDbType.NVarChar,50),  
                new SqlParameter(PARM_ProductPackageStatus,SqlDbType.NVarChar,10),    
            };
            return parms;
        }

        public override void SetParameters(PackageInfo Entity, params SqlParameter[] Parms)
        {
            Parms[0].Value = Entity.ProductType;
            Parms[1].Value = Entity.KCCSN1;
            Parms[2].Value = Entity.KCCSN2;
            Parms[3].Value = Entity.PEC;
            Parms[4].Value = Entity.CPC;
            Parms[5].Value = Entity.KCCSN;
            Parms[6].Value = Entity.NetWeight;
            Parms[7].Value = Entity.RLS;
            Parms[8].Value = Entity.QTY;
            Parms[9].Value = Entity.CountryOrigin;
            Parms[10].Value = Entity.WeekNum;
            Parms[11].Value = Entity.QCUser;
            Parms[12].Value = Entity.PackageUser;
            Parms[13].Value = Entity.Remark;
            Parms[14].Value = Entity.ProductPackageStatus;  
        }
        #endregion
   

    }
}
